<template>
  <div class="order">
    <div class="address" v-if="address.name" @click="toAddressList">
      <div class="item">
        <div class="list">
          <div class="addresslist">
            <div>
              <span>{{address.name}}</span>
              <div class="moren">默认</div>
            </div>
            <div class="info">
              <p>{{address.mobile}}</p>
              <p>{{address.address+address.address_detail}}</p>
            </div>
            <div></div>
          </div>
        </div>
      </div>
    </div>
    <div class="seladdress" v-else @click="toAdd">请选择默认地址</div>
    <div class="orderbox">
      <div class="item">
        <div>商品合计</div>
        <div>￥{{allPrice}}</div>
      </div>
      <div class="item">
        <div>运费</div>
        <div>免运费</div>
      </div>
      <div class="item">
        <div>优惠券</div>
        <div>暂无</div>
      </div>
    </div>
    <div class="cartlist">
      <div class="item" v-for="(item, index) in listData" :key="index">
        <div class="con">
          <div class="left">
            <div class="img">
              <img :src="item.list_pic_url" alt />
            </div>
            <div class="info">
              <p>{{item.goods_name}}</p>
              <p>￥{{item.retail_price}}</p>
            </div>
          </div>
          <div class="right">
            <div class="num">×{{item.number}}</div>
          </div>
        </div>
      </div>
    </div>
    <div class="bottom">
      <div>实付:￥{{allPrice}}</div>
      <div class="pay" @click="pay">支付</div>
    </div>
  </div>
</template>

<script>
import { get, post, getStorageOpenId } from "../../utils/index";
export default {
  data() {
    return {
      price: "",
      address: {},
      allPrice: "",
      openId: "",
      addressId: "",
      listData: []
    };
  },
  //-这个是小程序的生命周期
  onShow() {
    if (wx.getStorageSync("addressId")) {
      this.addressId = wx.getStorageSync("addressId");
    }
    this.openId = getStorageOpenId();
    this.getDetail();
  },
  methods: {
    toAdd() {
      wx.navigateTo({
        url: "/pages/addaddress/main"
      });
    },
    toAddressList() {
      wx.navigateTo({
        url: "/pages/addressSelect/main"
      });
    },
    async getDetail() {
      const data = await get("/order/detailAction", {
        openId: this.openId,
        addressId: this.addressId
      });
      console.log(data);
      if (data) {
        this.listData = data.goodsList;
        this.address = data.address;
      }
      this.listData.map(item => {
        // this.allPrice = Number(item.retail_price * item.number)+Number(this.allPrice);
        this.allPrice=data.price
      });
    },
    pay() {
      wx.showToast({
        title: "支付功能暂未开通",
        //-如果icon不为none 会有一个默认得打勾得图
        icon: "none",
        image: "",
        duration: 1500,
        mask: false,
        success: result => {},
        fail: () => {},
        complete: () => {}
      });
    }
  }
};
</script>

<style lang="less" scoped>
@import url("./style.less");
</style>